package com.ssy.lingxi.after.sale.controller.mobile;

import com.ssy.lingxi.after.sale.api.model.vo.request.CommonIdVO;
import com.ssy.lingxi.after.sale.model.constant.ReplaceGoodsReasonEnum;
import com.ssy.lingxi.after.sale.model.vo.request.*;
import com.ssy.lingxi.after.sale.model.vo.response.*;
import com.ssy.lingxi.after.sale.service.*;
import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu App - 售后换货相关接口
 * @author 伍将
 * @date 2020/12/30
 * @version 2.0.0
 */
@RestController
@RequestMapping("/as/mobile/replaceGoods")
public class MobileReplaceGoodsController extends BaseController {

    @Resource
    private IReplaceGoodsService replaceService;

    @Resource
    private IReplaceGoodsDetailService replaceGoodsDetailService;

    @Resource
    private IInnerWorkflowRecordService innerWorkflowRecordService;

    @Resource
    private IOuterWorkflowRecordService outerWorkflowRecordService;

    @Resource
    private IReplaceDeliveryGoodsService replaceDeliveryGoodsService;

    /**
     * 分页查询采购商售后换货
     * @author 伍将
     * @date 2020/12/30
     **/
/*    @RequestMapping(value = "/pageByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageByConsumer(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageByConsumer(getSysUser(httpRequest), pageVO);
    }*/

    /**
     * 换货原因-列表
     * @return
     */
    @RequestMapping(value = "/getReasonList", method = RequestMethod.GET)
    public Wrapper<List<DropdownItemVO>> getReasonList() {
        return Wrapper.success(ReplaceGoodsReasonEnum.toDropdownItems());
    }

    /**
     * 分页查询采购商售后换货-新
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryAppVO>> pageByConsumer(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageAppVO pageVO) {
        return replaceService.pageByConsumerApp(getSysUser(httpRequest), pageVO);
    }

    /**
     * 查询采购商售后换货详情
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/getDetailByConsumer", method = RequestMethod.GET)
    public Wrapper<ReplaceGoodsDetailAppVO> getDetailByConsumer(HttpServletRequest httpRequest, Long replaceId) {
        return replaceService.getDetailByApp(getSysUser(httpRequest), replaceId);
    }

    /**
     * 分页查询采购商售后换货商品
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageGoodsByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsDetailQueryVO>> pageGoodsByConsumer(HttpServletRequest httpRequest,@Valid ReplaceGoodsDetailPageVO pageVO) {
        return replaceGoodsDetailService.pageList(getSysUser(httpRequest),pageVO);
    }

    /**
     * 分页查询采购商售后换货内部流转记录
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageInnerWorkflowRecordByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceInnerWorkflowRecordVO>> pageInnerWorkflowRecordByConsumer(HttpServletRequest httpRequest, @Valid WorkflowPageVO pageVO) {
        return innerWorkflowRecordService.pageReplaceRecord(getSysUser(httpRequest), pageVO);
    }

    /**
     * 分页查询采购商售后换货外部流转记录
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageOuterWorkflowRecordByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceOuterWorkflowRecordVO>> pageOuterWorkflowRecordByConsumer(HttpServletRequest httpRequest, @Valid WorkflowPageVO pageVO) {
        return outerWorkflowRecordService.pageReplaceRecord(getSysUser(httpRequest), pageVO);
    }

    /**
     * 分页查询采购商待提交换货申请单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeSubmitByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageToBeSubmitByConsumer(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageToBeSubmitByConsumer(getSysUser(httpRequest), pageVO);
    }

    /**
     * 采购商保存换货申请单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/saveByConsumer", method = RequestMethod.POST)
    public Wrapper<Long> saveByConsumer(HttpServletRequest httpRequest, @RequestBody @Valid ReplaceGoodsSaveVO saveVO) {
        Wrapper<Long> save = replaceService.save(getSysUser(httpRequest), saveVO);
        if(save.getCode()== ResponseCode.SUCCESS.getCode()) {
            Wrapper<Void> submit = replaceService.submit(getSysUser(httpRequest), save.getData());
            if(submit.getCode()!= ResponseCode.SUCCESS.getCode()){
                return Wrapper.fail(submit.getCode(),submit.getMessage());
            }
        }
        return save;
    }

    /**
     * 采购商删除换货申请单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/deleteByConsumer", method = RequestMethod.POST)
    public Wrapper<Void> delete(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.delete(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 采购商提交换货申请单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/submitByConsumer", method = RequestMethod.POST)
    public Wrapper<Void> submit(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.submit(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 分页查询采购商待新增退货发货单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeAddReturnDeliveryGoods", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageToBeAddReturnDeliveryGoods(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageToBeAddReturnDeliveryGoods(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待新增退货发货单-新增退货发货单
     * @author 伍将
     * @date 2020/9/24
     **/
    @RequestMapping("/addReturnDeliveryGoods")
    public Wrapper<Long> addReturnDeliveryGoods(HttpServletRequest httpRequest,@RequestBody @Valid ReplaceDeliveryGoodsAddVO addVO) {
        return replaceService.addReturnDeliveryGoods(getSysUser(httpRequest),addVO);
    }

    /**
     *  待新增退货发货单-详情
     * @date 2021/8/13
     * @version 2.0.0
     */
    @RequestMapping(value = "/getReturnDeliveryGoodsDetail", method = RequestMethod.GET)
    public Wrapper<ReplaceGoodsBatchDetailVO> getReturnDeliveryGoodsDetail(HttpServletRequest httpRequest,Long returnDeliveryId) {
        return replaceService.getReturnGoodsDeliveryOrReceiveDetail(getSysUser(httpRequest), returnDeliveryId,false);
    }

    /**
     * 待新增退货发货单-审核退货发货单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/verifyReturnDeliveryGoods", method = RequestMethod.POST)
    public Wrapper<Void> verifyReturnDeliveryGoods(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.verifyReturnDeliveryGoodsByConsumer(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 分页查询采购商待新增物流单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeAddLogisticsByConsumer", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageToBeAddLogisticsByConsumer(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageToBeAddLogisticsByConsumer(getSysUser(httpRequest), pageVO);
    }

    /**
     * 分页查询采购商待退货发货单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeReturnDeliveryGoods", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageToBeReturnDeliveryGoods(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageToBeReturnDeliveryGoods(getSysUser(httpRequest), pageVO);
    }

    /**
     * 采购商确认退货发货
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/confirmReturnDeliveryGoods", method = RequestMethod.POST)
    public Wrapper<Void> confirmReturnDeliveryGoods(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.confirmReturnDeliveryGoods(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 采购商手工退货发货[已调整兼容手工多次:731]
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/manualReturnDeliveryGoods", method = RequestMethod.POST)
    public Wrapper<Void> manualReturnDeliveryGoods(HttpServletRequest httpRequest, @RequestBody @Valid ManualDeliveryGoodsVO deliveryGoodsVO) {
        return replaceService.manualReturnDeliveryGoods(getSysUser(httpRequest), deliveryGoodsVO);
    }

    /**
     * 分页查询采购商待确认退货回单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeConfirmReturnGoodsReceipt", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageToBeConfirmReturnGoodsReceipt(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageToBeConfirmReturnGoodsReceipt(getSysUser(httpRequest), pageVO);
    }

    /**
     * 采购商确认退货回单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/confirmReturnGoodsReceipt", method = RequestMethod.POST)
    public Wrapper<Void> confirmReturnGoodsReceipt(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.confirmReturnGoodsReceipt(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 分页查询列表页面搜索条件内容
     * @author 伍将
     * @date 2020/10/17
     **/
    @RequestMapping(value = "/pageItems", method = RequestMethod.GET)
    public Wrapper<ReplaceGoodsPageItemsVO> pageItems(HttpServletRequest httpRequest) {
        return replaceService.pageItems(getSysUser(httpRequest));
    }

    /**
     * 采购商继续退货发货
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/continueReturnDeliveryGoods", method = RequestMethod.POST)
    public Wrapper<Void> continueReturnDeliveryGoods(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.continueReturnDeliveryGoods(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 采购商确认全部退货回单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/confirmAllReturnGoodsReceipt", method = RequestMethod.POST)
    public Wrapper<Void> confirmAllReturnGoodsReceipt(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.confirmAllReturnGoodsReceipt(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 分页查询采购商待新增换货入库单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeAddReplaceGoodsStorage", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageToBeAddReplaceGoodsStorage(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageToBeAddReplaceGoodsStorage(getSysUser(httpRequest), pageVO);
    }

    /**
     * 采购商审核换货入库单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/verifyReplaceGoodsStorage", method = RequestMethod.POST)
    public Wrapper<Void> verifyReplaceGoodsStorage(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.verifyReplaceGoodsStorageByConsumer(getSysUser(httpRequest),commonIdVO.getDataId());
    }

    /**
     * 分页查询采购商待换货收货单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeReplaceReceiveGoods", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageToBeReplaceReceiveGoods(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageToBeReplaceReceiveGoods(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待新增换货入库单-新增换货收货单
     * @author 伍将
     * @date 2020/9/18
     **/
    @RequestMapping("/addReplaceGoodsStorage")
    public Wrapper<Void> addReplaceGoodsStorage(HttpServletRequest httpRequest,@RequestBody @Valid ReplaceReturnReceiveAddVO addVO) {
        return replaceService.addReplaceGoodsStorage(getSysUser(httpRequest),addVO);
    }

    /**
     *  待新增换货收货单-详情
     * @date 2021/8/13
     * @version 2.0.0
     */
    @RequestMapping(value = "/getReplaceGoodsStorageDetail", method = RequestMethod.GET)
    public Wrapper<ReplaceGoodsBatchDetailVO> getReplaceGoodsStorageDetail(HttpServletRequest httpRequest,Long replaceDeliveryId) {
        return replaceService.getReturnGoodsDeliveryOrReceiveDetail(getSysUser(httpRequest), replaceDeliveryId,false);
    }

    /**
     * 采购商确认换货收货
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/confirmReplaceReceiveGoods", method = RequestMethod.POST)
    public Wrapper<Void> confirmReplaceReceiveGoods(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.confirmReplaceReceiveGoods(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 采购商确认手工换货收货
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/confirmManualReplaceReceiveGoods", method = RequestMethod.POST)
    public Wrapper<Void> confirmManualReplaceReceiveGoods(HttpServletRequest httpRequest, @RequestBody @Valid CommonIdVO commonIdVO) {
        return replaceService.confirmManualReplaceReceiveGoods(getSysUser(httpRequest), commonIdVO.getDataId());
    }

    /**
     * 分页查询采购商待确认售后完成申请单
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/pageToBeComplete", method = RequestMethod.GET)
    public Wrapper<PageData<ReplaceGoodsQueryVO>> pageToBeComplete(HttpServletRequest httpRequest, @Valid ReplaceGoodsPageVO pageVO) {
        return replaceService.pageToBeComplete(getSysUser(httpRequest), pageVO);
    }

    /**
     * 采购商确认售后完成
     * @author 伍将
     * @date 2020/12/30
     **/
    @RequestMapping(value = "/confirmComplete", method = RequestMethod.POST)
    public Wrapper<Void> confirmComplete(HttpServletRequest httpRequest, @RequestBody @Valid ReplaceConfirmCompleteVO completeVO) {
        return replaceService.confirmComplete(getSysUser(httpRequest), completeVO);
    }

    /**
     * 物流服务-获取退货商品
     * @author 伍将
     * @date 2020/12/8
     **/
    @RequestMapping(value = "/pageReturnCommodityByLogistics", method = RequestMethod.GET)
    public Wrapper<PageData<CommodityQueryVO>> pageReturnCommodityByLogistics(@Valid CommodityPageVO pageVO) {
        return replaceDeliveryGoodsService.pageReturnCommodityByLogistics(pageVO);
    }

    /**
     * 物流服务-获取换货商品
     * @author 伍将
     * @date 2020/12/8
     **/
    @RequestMapping(value = "/pageReplaceCommodityByLogistics", method = RequestMethod.GET)
    public Wrapper<PageData<CommodityQueryVO>> pageReplaceCommodityByLogistics(@Valid CommodityPageVO pageVO) {
        return replaceDeliveryGoodsService.pageReplaceCommodityByLogistics(pageVO);
    }

    /**
     * 物流服务-获取退货申请单详情
     * @author 伍将
     * @date 2020/12/9
     **/
    @RequestMapping(value = "/pageReturnDetailByLogistics", method = RequestMethod.GET)
    public Wrapper<ApplyOrderQueryVO> pageReturnDetailByLogistics(Long replaceId) {
        return replaceService.pageReturnDetailByLogistics(replaceId);
    }

    /**
     * 物流服务-获取换货申请单详情
     * @author 伍将
     * @date 2020/12/9
     **/
    @RequestMapping(value = "/pageReplaceDetailByLogistics", method = RequestMethod.GET)
    public Wrapper<ApplyOrderQueryVO> pageReplaceDetailByLogistics(Long replaceId) {
        return replaceService.pageReplaceDetailByLogistics(replaceId);
    }
}
